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1_3-1/8*B_1_4-1/8*B_3_4-B_1_5-B_2_5+1/8*B_1_6+1/8*B_3_6)
]:
ADD:=[
C_1_1=-1/8*m_38+1/8*m_39+1/8*m_40-1/8*m_4-1/8*m_13+1/8*m_14-1/8*m_15-1/8*m_16-1/8*m_21-1/8*m_22-1/8*m_23-1/8*m_24-1/8*m_25+1/8*m_26+1/8*m_27+1/8*m_28+1/8*m_33-1/8*m_34-1/8*m_35+1/8*m_36-1/8*m_37+1/8*m_1-1/8*m_2-1/8*m_3,
C_2_1=-1/8*m_38+1/8*m_39-1/8*m_40+1/8*m_4-1/8*m_13-1/8*m_14+1/8*m_15-1/8*m_16+1/8*m_21-1/8*m_22+1/8*m_23-1/8*m_24+1/8*m_25+1/8*m_26+1/8*m_27-1/8*m_28+1/8*m_33+1/8*m_34-1/8*m_35-1/8*m_36+1/8*m_37+1/8*m_1+1/8*m_2-1/8*m_3,
C_3_1=-1/8*m_5+1/8*m_6-1/8*m_7-1/8*m_8+1/8*m_9-1/8*m_10-1/8*m_11+1/8*m_12+1/8*m_17-1/8*m_18+1/8*m_19+1/8*m_20+1/8*m_29+1/8*m_30+1/8*m_31-1/8*m_32,
C_1_2=m_9-m_10+m_11-m_12-m_13+m_14+m_15+m_16+m_17+m_18+m_19-m_20+m_21+m_22-m_23-m_24+m_29-m_30+m_31+m_32+m_33-m_34+m_35-m_36,
C_2_2=m_38+m_39+m_40+m_4+m_5-m_6+m_7+m_8+m_25+m_26-m_27+m_28+m_37+m_1-m_2+m_3,
C_3_2=m_9+m_10+m_11+m_12+m_13+m_14-m_15+m_16-m_17+m_18+m_19+m_20-m_21+m_22-m_23+m_24+m_29+m_30-m_31+m_32-m_33-m_34+m_35+m_36,
C_1_3=m_4-m_5-m_6+m_7-m_8+m_17+m_18+m_19-m_20-m_21-m_22+m_23+m_24+m_29-m_30+m_31+m_32+m_33-m_34+m_35-m_36-m_1-m_2-m_3,
C_2_3=m_38+m_39+m_40+m_9-m_10-m_11+m_12+m_13+m_14+m_15-m_16-m_25-m_26+m_27-m_28+m_37,
C_3_3=m_4+m_5-m_6-m_7-m_8-m_17+m_18+m_19+m_20+m_21-m_22+m_23-m_24-m_29-m_30+m_31-m_32+m_33+m_34-m_35-m_36+m_1+m_2-m_3,
C_1_4=-m_4-m_9+m_10+m_11-m_12+m_21-m_22-m_23+m_24+m_33+m_34+m_35+m_36-m_1+m_2-m_3,
C_2_4=m_38+m_39-m_40+m_5+m_6-m_7+m_8+m_13-m_14-m_15-m_16-m_17-m_18-m_19+m_20+m_25-m_26+m_27+m_28-m_29+m_30-m_31-m_32-m_37,
C_3_4=m_38-m_39-m_40+m_5+m_6+m_7-m_8+m_13-m_14+m_15+m_16-m_17-m_18+m_19-m_20+m_25-m_26-m_27-m_28-m_29+m_30+m_31+m_32+m_37,
C_1_5=-1/8*m_38+1/8*m_39+1/8*m_40-1/8*m_5-1/8*m_6-1/8*m_7+1/8*m_8-1/8*m_9-1/8*m_10+1/8*m_11+1/8*m_12-1/8*m_21-1/8*m_22-1/8*m_23-1/8*m_24-1/8*m_25+1/8*m_26+1/8*m_27+1/8*m_28-1/8*m_33+1/8*m_34+1/8*m_35-1/8*m_36-1/8*m_37,
C_2_5=-1/8*m_38+1/8*m_39-1/8*m_40-1/8*m_5+1/8*m_6+1/8*m_7+1/8*m_8+1/8*m_9+1/8*m_10+1/8*m_11+1/8*m_12-1/8*m_21+1/8*m_22-1/8*m_23+1/8*m_24-1/8*m_25-1/8*m_26-1/8*m_27+1/8*m_28-1/8*m_33-1/8*m_34+1/8*m_35+1/8*m_36+1/8*m_37,
C_3_5=1/8*m_4-1/8*m_13-1/8*m_14-1/8*m_15+1/8*m_16+1/8*m_17-1/8*m_18+1/8*m_19+1/8*m_20-1/8*m_29-1/8*m_30-1/8*m_31+1/8*m_32+1/8*m_1-1/8*m_2+1/8*m_3,
C_1_6=m_5-m_6+m_7+m_8+m_13+m_14+m_15-m_16+m_21-m_22-m_23+m_24-m_33-m_34-m_35-m_36,
C_2_6=-m_38-m_39+m_40+m_4+m_9-m_10+m_11-m_12+m_17+m_18+m_19-m_20+m_25-m_26+m_27+m_28+m_29-m_30+m_31+m_32+m_37-m_1-m_2-m_3,
C_3_6=m_38-m_39-m_40+m_4+m_9+m_10-m_11-m_12-m_17-m_18+m_19-m_20+m_25-m_26-m_27-m_28+m_29-m_30-m_31-m_32+m_37-m_1+m_2+m_3,
0=0]:
map(expand,subs(subs(MUL,ADD),C-A.B));
